<template>
	<view class="">
		<view style="display: flex;">
			<view style="width:180px ; height: 340px;">
				<u--image :showLoading="true"  :src="form.image" width="170px" height="330px" style="border: 5px saddlebrown solid;"    ></u--image>
				<view >
					名字：{{form.name}}  
				</view>
				<view >
					<span style="color: red;" >价格：</span>{{form.price}} <span>￥</span>
					
				</view>
			</view>
			<view style="width:100% ; height:340px;">
				<h2>势力：{{faaa.name}}</h2>
				<h3 style="color: goldenrod;">技能语音</h3>
				<rich-text :nodes="dee"></rich-text>
				
			</view>
		</view>
		<view  style="display: flex; margin-top: 50px;">
			<u-button  type="primary" text="加入购物车" @click="caradd(form)" color="red"></u-button>
			
				<u-button  type="primary" text="前往购物车" @click="goDetail" ></u-button>
			
			
		</view>
	</view>
	
	
</template>

<script>
	import {getMedicineAPIId,addShopCartAPI} from "../../services/api.js"
	import {
		dalImg
	} from "../../utils/tools.js"
	export default {
		data() {
			return {
				id:'',
				faaa:[],
				form:[],
				aee:"",
				bee:"",
				cee:"",
				dee:"",
				dat:{
					  amount: 1,
					  medicine: "",
					  price: 1
				}
				
				
			}
		},
		
		onLoad(ev){
			this.id=ev.id
			console.log(this.id)
			getMedicineAPIId(this.id).then(res=>{
			  console.log(res);
			  console.log(res.data.image);
			  res.data.image=dalImg(res.data.image)
			  

			  this.form=res.data
			  this.aee=res.data.desc.replaceAll("？","？<br/>");
			 
			  this.bee=this.aee.replaceAll("：",":<br/>");
			   this.cee=this.bee.replaceAll("。","。<br/>");
			     this.dee=this.cee.replaceAll("！","！<br/>");
			   this.faaa=this.form.category
			 
			   console.log(this.aee);
			  console.log(this.form);
			   
			   
			  
			 
			})
		},
		methods: {
			caradd(form){
				this.dat.medicine=form.id
				this.dat.price=form.price
				 console.log(this.dat);
				  addShopCartAPI(this.dat).then(res=>{
				         console.log(res);
						 if(res.success==true){
								uni.showToast({
									title: '添加成功',
									icon:"success",
									duration: 300})
						 }
				        
				       })
			},
			goDetail(){
						uni.switchTab({
						    url: '/pages/cart/cart'
						});
					}
			
		}
		
	}
</script>

<style>

</style>
